// 用户登录信息仓库
import {UserLogin} from '@/services/UserService'

export default{
    namespaced:true,//开启命名空间，方便mapState使用
    state:{
        data:null,
        isLoading:false,
    },
    mutations:{
        setData(state,payload){
            state.data = payload 
        },
        setIsLoading(state,payload){
            state.isLoading = payload 
        },
    },
    actions:{
       async login(context,payload){//context相当于this.$store
        var flag = false;
        context.commit("setIsLoading",true);
        var resp = await UserLogin(payload);
        console.log(resp);//返回的是response对象
        context.commit("setData",resp.data);
        context.commit("setIsLoading",false);
        
        if(resp.code == 0){
            flag = true;
        }
        return flag;
        
        }
    }
}